{layout name="layout/header" /}
<link href="root/css/plugins/iCheck/custom.css" rel="stylesheet">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>新添管理员</h5>
                        <div class="ibox-tools">
                            <a type="button" class="btn btn-primary btn-sm" href="{:url('admin/index')}">返回列表页</a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="form" action="{:url('admin/add')}">
                            <div class="form-group">
                                <label class="col-sm-1 control-label">用户名</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control"  name="username" placeholder="用户名">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label">用户组</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b" name="role_id">
                                        {volist name="$data" id="vo"}
                                        <option value="{$vo.id}">{$vo.name}</option>
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label">登录密码</label>
                                <div class="col-sm-4">
                                    <input type="password" name="password" id="password" class="form-control">
                                    <span>登录密码不能少于6位</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label">重复密码</label>
                                <div class="col-sm-4">
                                    <input type="password" name="confirm_password" class="form-control">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label">备注</label>
                                <div class="col-sm-4">
                                    <input type="text" name="remark" class="form-control" placeholder="备注">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label">状态</label>
                                <div class="col-sm-10">
                                    <div class="radio i-checks">
                                        <label><input type="radio" checked value="1" name="status">正常</label>
                                        <label><input type="radio"  value="0" name="status"> 禁用</label>
                                    </div>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary">保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
    </div>
</div>


<!-- iCheck -->
<script src="root/js/plugins/iCheck/icheck.min.js"></script>
<!--layer-->
<script src="root/js/plugins/layer/layer.min.js"></script>

<script src="root/js/plugins/validate/jquery.validate.min.js"></script>
<script src="root/js/plugins/validate/messages_zh.min.js"></script>
<script>
    $(document).ready(function () {
        checks();
        //单选，复选按钮
        function checks () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green'
            })
        };

    });

</script>
<script>
    $(function () {
        $.validator.addMethod("unique",function(value,element,params){
            var a = 0;
            $.ajax({
                url:"{:url('ajax_unique_username')}",
                type:"post",
                dataType:"json",
                async:false,
                data:{username:value},
                success:function (res) {
                    if(res.code == 1){
                        a = 1;
                    }
                }
            });

            if(a == 0){
                return true;
            }else {
                return false;
            }
        },"用户名已存在");

        $("#form").validate({
            rules: {
                username:{unique:true,required:true},
                password: {
                    required: true,
                    minlength: 6
                },
                confirm_password: {
                    required: true,
                    minlength: 6,
                    equalTo: "#password"
                }
            }
        })
    })
</script>
